package com.zhss.designpattern.factory;

public class AbstractFactoryPatternDemo {

    public interface ProductA{
        void execute();
    }

    public interface ProductB{
        void execute();
    }

    static class Product1 implements ProductA{

        public void execute() {
            System.out.println("-----执行Product1方法！-----");
        }
    }

    static class Product2 implements ProductA{

        public void execute() {
            System.out.println("-----执行Product2方法！-----");
        }
    }

    static class Product3 implements ProductB{

        public void execute() {
            System.out.println("-----执行Product3方法！-----");
        }
    }

    static class Product4 implements ProductB{

        public void execute() {
            System.out.println("-----执行Product4方法！-----");
        }
    }

    interface Factory{
        ProductA createProductA();
        ProductB createProductB();
    }

    static class Factory1 implements Factory{
        private static Factory1 instance = new Factory1();
        public static Factory getInstance(){
            return instance;
        }
        @Override
        public ProductA createProductA() {
            return new Product1();
        }
        @Override
        public ProductB createProductB() {
            return new Product3();
        }
    }

    static class Factory2 implements Factory{
        private static Factory2 instance = new Factory2();
        public static Factory getInstance(){
            return instance;
        }
        @Override
        public ProductA createProductA() {
            return new Product2();
        }
        @Override
        public ProductB createProductB() {
            return new Product4();
        }
    }

    public static void main(String[] args) {
       ProductA product1 = Factory1.getInstance().createProductA();
       ProductB product2 = Factory1.getInstance().createProductB();

       ProductA product3 = Factory2.getInstance().createProductA();
       ProductB product4 = Factory2.getInstance().createProductB();

       product1.execute();
       product2.execute();
       product3.execute();
       product4.execute();
    }
}
